import { useCallback, useState } from 'react';

/**
 *
 * @param initialState 初始值
 *
 *
 * @example
 *
 *
 *   const [state, setState] = useSetState<State>({
        hello: '',
        count: 0,
      });

    setState({ hello: 'world' }) // state: {hello: 'world' , count: 0, }
 *
 */
const useSetState = <T extends object>(
  initialState: T = {} as T,
): [T, (patch: Partial<T> | ((prevState: T) => Partial<T>)) => void] => {
  const [state, setState] = useState<T>(initialState);
  const setMergeState = useCallback(
    (patch) => {
      setState((prevState) =>
        Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch),
      );
    },
    [setState],
  );

  return [state, setMergeState];
};

Taro.request({
  url: 'http://10.190.84.29:9527/fta-trade/order/shipper/getCompletedOrders',
  method: 'POST',
  data: JSON.stringify({
    
  }),
  success: () => {

  },
  fail: () => {

  }
})

export default useSetState;